package com.test.ssm.controller;

import com.test.ssm.pojo.Flight;
import com.test.ssm.pojo.Ticket;
import com.test.ssm.service.FlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author 徒有琴
 */
@Controller
public class FlightController {
    @Autowired
    private FlightService flightService;

    @RequestMapping("index.html")
    public String index(String time, String off, String arrive, Model model) {
        if (StringUtils.isEmpty(time) || StringUtils.isEmpty(off) || StringUtils.isEmpty(arrive)) {
            return "index";
        }
        List<Flight> flights = flightService.getFlights(time, off, arrive);
        model.addAttribute("flights", flights);
        return "index";
    }

    @RequestMapping("ticket.html")
    @ResponseBody
    public List<Ticket> ticket(Integer id) {
        return flightService.getTicketByFlightId(id);
    }
}
